package com.netty.client;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import org.springframework.stereotype.Component;

/**
 * 负责监听启动时连接失败，重新连接功能
 * @author
 */
@Component
public class ConnectionListener implements ChannelFutureListener {
    @Override
    public void operationComplete(ChannelFuture channelFuture) throws Exception {
        if (!channelFuture.isSuccess()) {
            System.out.println("-------------服务端重新连接-----------------");
            Thread.sleep(5000);
            new NettyClient().start();
        } else {
            System.err.println("服务端链接成功...");
        }
    }
}
